package com.tanhua.model.vo;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.SimpleDateFormat;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/11 21:46
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommentAdminVo {

    private String id;
    private String nicaname;
    private Integer userId;
    private String content;
    private String createDate;

    public static CommentAdminVo init(UserInfo userInfo, Comment comment){

        CommentAdminVo vo = new CommentAdminVo();
        if (comment != null) {
            vo.setId(comment.getId().toHexString());
            vo.setUserId(comment.getUserId().intValue());
            vo.setContent(comment.getContent());
            String format = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(comment.getCreated());
            vo.setCreateDate(format);
        }
        if (userInfo != null){
            vo.setNicaname(userInfo.getNickname());
        }

        return vo;
    }

}
